package org.hagopa.games.moneypool.dblayer;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.hagopa.games.moneypool.dblayer.Connector.DBConnector;

public class PlayerDataAdopt implements IDataAdopt{
	private long userId;
	private String dbquery = "";
	private String username = "Player";
        
	
	public PlayerDataAdopt(long uId){
		this.userId = uId;
                System.out.println("[PlayerDataAdopt] - User Id:" + this.userId);
		this.dbquery = "SELECT * FROM users WHERE id="+this.userId+"";
	}
	
	public boolean requestDB()
	{
		ResultSet rs = null;
            Statement stmt = null;
            try {

                    stmt = DBConnector.getConn().createStatement();

                    rs = stmt.executeQuery(this.dbquery);
                    while(rs.next())
                    {
                            this.username = rs.getString("name");
                            System.out.println(" Username: " + this.username);
                    //if(false == this.parseDBresponse(rs))
                    //	return false;
                    }
                    rs.close();
                    stmt.close();

            } catch (SQLException e) {
                                    // TODO Auto-generated catch block
                            e.printStackTrace();
                            return false;
            }
            return true;
	}
	
	public String getQuery() {
		return this.dbquery;
	}

	
	public String getQueryType() {
		// TODO Auto-generated method stub
		return "sql";
	}

	
	public boolean parseDBresponse(ResultSet rs) {
		try {
			System.out.println("Got RS");
			//this.username = rs.getString("name");
			System.out.println(" ID" + rs.getInt(0));	
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}
		return true;
	}

	public String getDbquery() {
		return dbquery;
	}

	public void setDbquery(String dbquery) {
		this.dbquery = dbquery;
	}

	public long getUserId() {
		return userId;
	}

	public String getUsername() {
		return username;
	}

}
